import { Behaviour, getGameObjectById, Transform, core, GameObject } from "../gameengine";
import { ColliderSystem } from "../rect/ColliderSystem";
import { RectCollider, RectColliderType } from "../rect/RectCollider";
import {  fightingbear, fightingbear2, fightingbear3} from "../data";
import{user}from "../user";

export class EFbear extends Behaviour {
    ft: GameObject;
    private flag = false;


    // private speedX = 0;
    // private speedY = 0;


    protected onStart() {
    }

    protected onUpdate(advancedTime: number) {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        const collider = this.displayObject.getScript(RectCollider);
        const nextCollider = {
            left: collider.left + -4,
            right: collider.right + 4,
            top: collider.top + -4,
            bottom: collider.bottom + 4
        }
        const hitTestResult1 = colliderSystem.check(nextCollider, RectColliderType.MAINROLE);
        if (hitTestResult1 && !this.ft) {
            this.flag = true;
        }

        if (this.ft && !this.ft.parent) { 
            this.ft = null;
        }

        if (this.flag) {
            if (!this.ft) {
                
                this.ft = core.createPrefab(fightingbear);
                const scene = getGameObjectById("UIScene");
                scene.addChild(this.ft);
            }
            this.flag = false;
        }

        if (this.flag == true) {
            // marshal.changeState(new MarshalGamingState());

            if (!this.ft) {

                
                this.ft = core.createPrefab(fightingbear);

                const scene = getGameObjectById("UIScene");
                scene.addChild(this.ft);
                // scene.addChild(this.ui);
            }


        }

        

    }


}

export class EFbear2 extends Behaviour {
    ft: GameObject;
    private flag = false;


    // private speedX = 0;
    // private speedY = 0;


    protected onStart() {
    }

    protected onUpdate(advancedTime: number) {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        const collider = this.displayObject.getScript(RectCollider);
        const nextCollider = {
            left: collider.left + -4,
            right: collider.right + 4,
            top: collider.top + -4,
            bottom: collider.bottom + 4
        }
        const hitTestResult1 = colliderSystem.check(nextCollider, RectColliderType.MAINROLE);
        if (hitTestResult1 && !this.ft) {
            this.flag = true;
        }

        if (this.ft && !this.ft.parent) { 
            this.ft = null;
        }

        if (this.flag) {
            if (!this.ft) {
                
                this.ft = core.createPrefab(fightingbear2);
                const scene = getGameObjectById("UIScene");
                scene.addChild(this.ft);
            }
            this.flag = false;
        }

        if (this.flag == true) {
            // marshal.changeState(new MarshalGamingState());

            if (!this.ft) {

                
                this.ft = core.createPrefab(fightingbear2);

                const scene = getGameObjectById("UIScene");
                scene.addChild(this.ft);
                // scene.addChild(this.ui);
            }


        }

        

    }


}

export class EFbear3 extends Behaviour {
    ft: GameObject;
    private flag = false;


    // private speedX = 0;
    // private speedY = 0;


    protected onStart() {
    }

    protected onUpdate(advancedTime: number) {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        const collider = this.displayObject.getScript(RectCollider);
        const nextCollider = {
            left: collider.left + -4,
            right: collider.right + 4,
            top: collider.top + -4,
            bottom: collider.bottom + 4
        }
        const hitTestResult1 = colliderSystem.check(nextCollider, RectColliderType.MAINROLE);
        if (hitTestResult1 && !this.ft) {
            this.flag = true;
        }

        if (this.ft && !this.ft.parent) { 
            this.ft = null;
        }

        if (this.flag) {
            if (!this.ft) {
                
                this.ft = core.createPrefab(fightingbear3);
                const scene = getGameObjectById("UIScene");
                scene.addChild(this.ft);
            }
            this.flag = false;
        }

        if (this.flag == true) {
            // marshal.changeState(new MarshalGamingState());

            if (!this.ft) {

                
                this.ft = core.createPrefab(fightingbear3);

                const scene = getGameObjectById("UIScene");
                scene.addChild(this.ft);
                // scene.addChild(this.ui);
            }


        }

        

    }


}